<template>
<div class="main-box">
    <van-nav-bar
            title="发表评价"
            left-text="返回"
            left-arrow
            @click-left="onClickLeft"
    />
    <div>

            <template  v-for="(goods) in checkedShopCart">

                    <van-card
                            :key="goods.id"
                            :num="goods.count===undefined?1:goods.count"
                            :desc="goods.name+goods.colorName+goods.sizeName"
                            :price="goods.price"
                            :title="goods.title"
                            :thumb=baseURL1+goods.img
                    >
                    </van-card>
                <van-button round v-show="evaBtn" @click="showEva(goods.id)" color="linear-gradient(to right, #ff6034, #ee0a24)"  size="small" style="margin-left:270px;margin-top:-10px;width:80px">
                                    评价
                                     </van-button>
                <van-button v-show="overEva" round color="linear-gradient(to right, #ff6034, #ee0a24)"  size="small" style="margin-left:270px;margin-top:-10px;width:80px" disabled>
                    已评价
                </van-button>
</template>
    </div>
    <van-action-sheet v-model="show" title="评价">
        <div class="content">
            <van-row type="flex" justify="center">
                <van-col span="8" offset="4"><span style="font-size:16px">描述相符：</span></van-col>
                <van-col span="12">  <van-rate v-model="value" icon="like" void-icon="like-o" /></van-col>
            </van-row>
            <div style="margin-top: 10px">
                <van-field
                        v-model="message"
                        rows="3"
                        autosize
                        label="评价"
                        type="textarea"
                        placeholder="优质的评价帮助更多的人哦"
                />
            </div>
            <van-button round color="linear-gradient(to right, #ff6034, #ee0a24)"  size="small" style="margin-left:100px;margin-top:50px;width:100px" @click="okEva()">
                发表
            </van-button>
        </div>
    </van-action-sheet>

</div>
</template>

<script>
    import img, {getAllOrder, putEva} from "@/api/api";
    import {Toast} from "vant";

    export default {
        name: "toEvaluate",
        created() {
            this.checkedShopCart=this.$route.query.checkedShopCart
        },
        data(){
            return {
                baseURL1:img.src,
                checkedShopCart: [],
                show:false,
                value:3,
                message:"",
                evaBtn:true,
                overEva:false,
                gid:"",

            }
        },
        methods: {
            onClickLeft() {
                this.$router.go(-1);
            },
            showEva(gid){
                this.show=true
                this.gid=gid
            },
            okEva() {
                if(this.message==""||this.message==null){
                    Toast("内容不能为空")
                }else{
                    putEva(this.message,this.gid,this.$route.query.uuid).then((resp) => {
                        if (resp.data.code === 2000) {
                            Toast("发表成功")
                            this.evaBtn = false
                            this.overEva = true;
                            this.show = false;

                        } else {
                            Toast(resp.data.message);
                        }
                    })
                }

            }

    }
    }
</script>

<style scoped>
    .main-box{
        height: 100%;
        background-color: white;
    }
    .content {
        padding: 16px 16px 160px;
    }
</style>